﻿using strange.extensions.context.api;
using strange.extensions.dispatcher.eventdispatcher.api;
using strange.extensions.mediation.impl;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

namespace NormalBattleIoc
{
    public enum TankOperationEvent
    {
          ZhuPaoAttack,
          FuPaoAttack,
          SEAttack,
          TankUseTool,
          TankFangWei,
          TankTaoPao
    }

  

    public class TankOperationMediator : Mediator
    {

        [Inject]
        public TankOperationView view { get; set; }

        [Inject(ContextKeys.CONTEXT_DISPATCHER)]//全局的dispatcher
        public IEventDispatcher dispatcher { get; set; }

        /// <summary>
        /// 这里做初始化的操作，相当于start
        /// </summary>
        public override void OnRegister()
        {
           // view.ShowThisUI();

            AddAttackButtonClickFunc();

            dispatcher.AddListener(BattleUIEvent.OPEN_Tank_OperationPanel , OnOpenTank_OperationPanel);

            dispatcher.AddListener(BattleUIEvent.Close_All_Panel, OnCloseAll_Panel);
        }

        private void OnCloseAll_Panel(IEvent payload)
        {
            view.CloseThisUI();
        }

        private void OnOpenTank_OperationPanel(IEvent payload)
        {
            view.ShowThisUI();
        }

        void AddAttackButtonClickFunc()
        {
            //view.buttonClicked.AddListener(doManagement.Dispatch);
            if (view.btn_Zhupao_attack != null)
            {
                view.btn_Zhupao_attack.onClick.AddListener(delegate ()
                {

                     dispatcher.Dispatch( TankOperationEvent.ZhuPaoAttack  );
                     view.CloseThisUI();
                });
            }

        }
    }
}